package com.qf.test;

import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;

import java.util.UUID;

/**
 * Jedis连接池操作
 * @author zjw
 */
public class Demo4 {

    @Test
    public void pool(){
        //1. 创建连接池
        JedisPool pool = new JedisPool("192.168.41.98",6379);

        //2. 获取连接对象
        Jedis jedis = pool.getResource();

        System.out.println(System.currentTimeMillis());
        //3.1 采用管道，向Redis存储10W条数据
        Pipeline pipelined = jedis.pipelined();
        for (int i = 0; i < 100000; i++) {
            pipelined.setex("pipelined" + i,500,UUID.randomUUID().toString());
        }
        pipelined.sync();
        System.out.println(System.currentTimeMillis());

        //4. 返还连接对象
        jedis.close();
    }


}
